
package com.jf.cloud.order.task;


import com.jf.cloud.api.feign.SearchOrderTaskFeignClient;
import com.jf.cloud.common.exception.LuckException;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 订单定时任务
 *
 * @author zz
 */
@Component
public class OrderTask {

    @Autowired
    private SearchOrderTaskFeignClient searchOrderTaskFeignClient;

    /**
     * 订单结算
     */
    @XxlJob("settledOrder")
    public void settledOrder(){
        ServerResponseEntity serverResponseEntity = searchOrderTaskFeignClient.settledOrder();
        if (serverResponseEntity.isFail()) {
            throw new LuckException(serverResponseEntity.getMsg());
        }
    }


    /**
     * 确认收货
     */
    @XxlJob("confirmOrder")
    public void confirmOrder(){
        ServerResponseEntity serverResponseEntity = searchOrderTaskFeignClient.confirmOrder();
        if (serverResponseEntity.isFail()) {
            throw new LuckException(serverResponseEntity.getMsg());
        }
    }

    /**
     * 预售订单，尾款时间过期未支付时的处理
     */
    @XxlJob("balanceTimeExpireOrder")
    public void handleBalanceTimeExpireOrder() {
        ServerResponseEntity serverResponseEntity = searchOrderTaskFeignClient.handleBalanceTimeExpireOrder();
        if (serverResponseEntity.isFail()) {
            throw new LuckException(serverResponseEntity.getMsg());
        }
    }

    /**
     * 预售订单，尾款时间开始时尾款金额为0的处理
     */
    @XxlJob("balanceTimeStartOrder")
    public void handlerBalanceTimeStartOrder(){
        ServerResponseEntity serverResponseEntity = searchOrderTaskFeignClient.handlerBalanceTimeStartOrder();
        if (serverResponseEntity.isFail()) {
            throw new LuckException(serverResponseEntity.getMsg());
        }
    }

    /**
     * 0点执行一遍检查采购订单支付状态定时任务
     */
    @XxlJob("checkPurchaseOrderPayStatus")
    public void checkPurchaseOrderPayStatus() {
        ServerResponseEntity serverResponseEntity = searchOrderTaskFeignClient.checkPurchaseOrderPayStatus();
        if (serverResponseEntity.isFail()) {
            throw new LuckException(serverResponseEntity.getMsg());
        }
    }
}
